<template>
  <div>
    <el-card class="box-card" style="margin: auto">
      <el-row>
        <el-col :span="10" style="margin-top: 5px">Total {{totalfile}} files</el-col>
        <el-col :span="8"
          ><div class="demo-input-suffix">
            Search
            <el-input
              placeholder=""
              prefix-icon="el-icon-search"
              v-model="keyword"
              style="width: 200px"
              @keypress.enter.native="search"
            >
            </el-input></div
        ></el-col>
      </el-row>
      <el-table
        :data="
          fileList
        "
        style="width: 100%"
        border
        stripe
      >
        <el-table-column prop="dname" label="文件名"> </el-table-column>
        <el-table-column prop="dsize" label="大小" width="280">
        </el-table-column>
        <el-table-column prop="ctime" label="创建日期"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="80">
          <template slot-scope="scope">
            <a
              class="el-icon-download"
              v-bind:href="
                fileList[scope.$index].path
              "
            ></a>
          </template>
        </el-table-column>
      </el-table>
      <el-row style="margin-top: 25px">
        <el-col>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 20, 40]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalfile"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import filesApi from "@/api/ky";

export default {
  data() {
    return {
      keyword: "",
      currentPage: 1, //初始页
      pagesize: 10,
      fileList: [],
      paths: [],
      totalfile: 0,
    };
  },
  props: ["subject"],
  methods: {
    search() {
      if (this.keyword.trim == "") {
        return this.fileList;
      }
      return this.getFileList();
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange(size) {
      this.pagesize = size;
      this.getCourseTable();
      //  console.log(this.pagesize)  //每页下拉显示数据
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
      this.getCourseTable();
      // console.log(this.currentPage)  //点击第几页
    },
    getCourseTable() {
      filesApi.getCourseFiles(this.subject).then((res) => {
         //console.log(this.subject)
        //console.log(res.data.list);
        this.fileList = res.data.rows;
        this.totalfile = res.data.total;
      });
    },
  },
  watch: {
    "subject":function(){
      this.getCourseTable()
    }
  },
  
};
</script>

<style>
.el-row {
  margin-bottom: 15px;
}
</style>